package com.luna.cloudworm.product.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * User: haitao
 * Date: 2020/6/19
 */
//Spring boot鏂瑰紡
@EnableTransactionManagement
@Configuration
@MapperScan("com.luna.cloudworm.product.dao")
public class MybatisPlusConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // 璁剧疆璇锋眰鐨勯〉闈㈠ぇ浜庢渶澶ч〉鍚庢搷浣滐紝 true璋冨洖鍒伴椤碉紝false 缁х画璇锋眰  榛樿false
         paginationInterceptor.setOverflow(true);
        // 璁剧疆鏈�澶у崟椤甸檺鍒舵暟閲忥紝榛樿 500 鏉★紝-1 涓嶅彈闄愬埗
         paginationInterceptor.setLimit(1000);
        // 寮�鍚� count 鐨� join 浼樺寲,鍙拡瀵归儴鍒� left join
        paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
        return paginationInterceptor;
    }
}